home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / cxref-1.001 / cxref-1~ / cxref / query / output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-24  |  7.1 KB  |  255 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/query/RCS/output.c 1.3 1996/02/24 14:53:48 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.0
  5.   ******************/ /******************
  6.   Written by Andrew M. Bishop
  7.  
  8.   This file Copyright 1995,96 Andrew M. Bishop
  9.   It may be distributed under the GNU Public License, version 2, or
  10.   any higher version.  See section COPYING of the GNU Public license
  11.   for conditions under which this file may be redistributed.
  12.   ***************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include "../memory.h"
  19. #include "../datatype.h"
  20. #include "../cxref.h"
  21. #include "query.h"
  22.  
  23.  
  24. /*+ The command line switch that sets the amount of cross referencing to do. +*/
  25. extern int option_xref;
  26.  
  27. extern File *files;             /*+ The files that are queried. +*/
  28. extern int n_files;             /*+ The number of files referenced. +*/
  29.  
  30. extern Function *functions;     /*+ The functions that are queried. +*/
  31. extern int n_functions;         /*+ The number of functions referenced. +*/
  32.  
  33. extern Variable *variables;     /*+ The variables that are queried. +*/
  34. extern int n_variables;         /*+ The number of variables referenced. +*/
  35.  
  36. extern Typedef *typedefs;       /*+ The type definitions that are queried. +*/
  37. extern int n_typedefs;          /*+ The number of typedefs referenced. +*/
  38.  
  39. /* Local fuctions */
  40.  
  41. static void OutputFile(File file);
  42. static void OutputInclude(Include incl,int depth);
  43. static void OutputFunction(Function func);
  44. static void OutputVariable(Variable var);
  45. static void OutputTypedef(Typedef type);
  46.  
  47.  
  48. /*++++++++++++++++++++++++++++++++++++++
  49.   Ouput the cross references for the named thing.
  50.  
  51.   char* name The name of the object to ouput the cross references for.
  52.   ++++++++++++++++++++++++++++++++++++++*/
  53.  
  54. void OutputCrossRef(char* name)
  55. {
  56.  int i,any=0;
  57.  
  58.  for(i=0;i<n_files;i++)
  59.     if(!strcmp(name,files[i]->name))
  60.        {OutputFile(files[i]);any++;}
  61.  
  62.  for(i=0;i<n_functions;i++)
  63.     if(!strcmp(name,functions[i]->name))
  64.       {OutputFunction(functions[i]);any++;}
  65.  
  66.  for(i=0;i<n_variables;i++)
  67.     if(!strcmp(name,variables[i]->name))
  68.       {OutputVariable(variables[i]);any++;}
  69.  
  70.  for(i=0;i<n_typedefs;i++)
  71.     if(!strcmp(name,typedefs[i]->name))
  72.       {OutputTypedef(typedefs[i]);any++;}
  73.  
  74.  if(!any)
  75.     printf("cxref-query: No match for '%s'.\n",name);
  76. }
  77.  
  78. /*++++++++++++++++++++++++++++++++++++++
  79.   Print out the information for a file.
  80.  
  81.   File file The file to output the information for.
  82.   ++++++++++++++++++++++++++++++++++++++*/
  83.  
  84. static void OutputFile(File file)
  85. {
  86.  int i;
  87.  Include inc;
  88.  Function func;
  89.  Variable var;
  90.  Typedef type;
  91.  
  92.  printf("File: %s\n\n",file->name);
  93.  
  94.  for(inc=file->includes,i=0;inc;inc=inc->next,i++)
  95.    {
  96.     printf("    %s %c%s%c\n",i?"          ":"Includes :",inc->scope==GLOBAL?'<':'"',inc->name,inc->scope==GLOBAL?'>':'"');
  97.     OutputInclude(inc,1);
  98.    }
  99.  printf("\n");
  100.  
  101.  for(func=file->functions,i=0;func;func=func->next,i++)
  102.     printf("    %s %s\n",i?"          ":"Functions:",func->name);
  103.  printf("\n");
  104.  
  105.  for(var=file->variables,i=0;var;var=var->next,i++)
  106.     printf("    %s %s\n",i?"          ":"Variables:",var->name);
  107.  printf("\n");
  108.  
  109.  for(type=file->typedefs,i=0;type;type=type->next,i++)
  110.     printf("    %s %s\n",i?"          ":"Types    :",type->name);
  111.  printf("\n");
  112.  
  113.  if(option_xref&XREF_FILE)
  114.     for(i=0;i<file->inc_in.n;i++)
  115.        printf("   %s %s\n",i?"            ":"Included in:",file->inc_in.s[i]);
  116.  
  117.  if(option_xref&XREF_FUNC)
  118.     for(i=0;i<file->f_refs.n;i++)
  119.        printf("   %s %s\n",i?"            ":"Refs func  :",file->f_refs.s[i]);
  120.  
  121.  if(option_xref&XREF_VAR)
  122.     for(i=0;i<file->v_refs.n;i++)
  123.        printf("   %s %s\n",i?"            ":"Refs var   :",file->v_refs.s[i]);
  124. }
  125.  
  126.  
  127. /*++++++++++++++++++++++++++++++++++++++
  128.   Print out the information for an include file.
  129.  
  130.   Include incl The include file to output the information for.
  131.  
  132.   int depth The depth of the includes.
  133.   ++++++++++++++++++++++++++++++++++++++*/
  134.  
  135. static void OutputInclude(Include incl,int depth)
  136. {
  137.  int c,i;
  138.  Include inc;
  139.  
  140.  for(inc=incl->includes,c=0;inc;inc=inc->next,c++)
  141.    {
  142.     for(i=0;i<depth;i++) fputs("   ",stdout);
  143.     printf("               %c%s%c\n",inc->scope==GLOBAL?'<':'"',inc->name,inc->scope==GLOBAL?'>':'"');
  144.     OutputInclude(inc,depth+1);
  145.    }
  146. }
  147.  
  148.  
  149. /*++++++++++++++++++++++++++++++++++++++
  150.   Print out the information for a function.
  151.  
  152.   Function func The function to output the information for.
  153.   ++++++++++++++++++++++++++++++++++++++*/
  154.  
  155. static void OutputFunction(Function func)
  156. {
  157.  int i;
  158.  
  159.  printf("Function: %s ",func->name);
  160.  
  161.  switch(func->scope)
  162.    {
  163.    case LOCAL:           printf("[Local]\n"); break;
  164.    case GLOBAL:          printf("[Global]\n"); break;
  165.    case LOCAL+INLINED:   printf("[Local inline]\n"); break;
  166.    case INLINED:         printf("[inline]\n"); break;
  167.    default:              ;
  168.    }
  169.  
  170.  if(option_xref&XREF_FUNC)
  171.    {
  172.     for(i=0;i<func->calls.n;i++)
  173.        printf("   %s %s\n",i?"            ":"Calls      :",func->calls.s[i]);
  174.  
  175.     for(i=0;i<func->called.n;i++)
  176.        printf("   %s %s\n",i?"            ":"Called from:",func->called.s[i]);
  177.  
  178.     for(i=0;i<func->used.n;i++)
  179.       {
  180.        if(func->used.s[i][0]=='$')
  181.           printf("   %s %s\n",i?"            ":"Used in    :",&func->used.s[i][1]);
  182.        else
  183.           printf("   %s %s\n",i?"            ":"Used in    :",func->used.s[i]);
  184.       }
  185.  
  186.     for(i=0;i<func->f_refs.n;i++)
  187.        printf("   %s %s\n",i?"            ":"Refs func  :",func->f_refs.s[i]);
  188.    }
  189.  
  190.  if(option_xref&XREF_VAR)
  191.     for(i=0;i<func->v_refs.n;i++)
  192.        printf("   %s %s\n",i?"            ":"Refs var   :",func->v_refs.s[i]);
  193.  
  194.  printf("\n");
  195. }
  196.  
  197.  
  198. /*++++++++++++++++++++++++++++++++++++++
  199.   Print out the information for a variable.
  200.  
  201.   Variable var The variable to output the information for.
  202.   ++++++++++++++++++++++++++++++++++++++*/
  203.  
  204. static void OutputVariable(Variable var)
  205. {
  206.  int i;
  207.  
  208.  printf("Variable: %s ",var->name);
  209.  
  210.  switch(var->scope)
  211.    {
  212.    case LOCAL:           printf("[Local]\n"); break;
  213.    case GLOBAL:          printf("[Global definition]\n"); break;
  214.    case EXTERNAL:        printf("[External]\n"); break;
  215.    case EXTERN_H:        printf("[External from header file]\n"); break;
  216.    case EXTERNAL+GLOBAL: printf("[Global and External]\n"); break;
  217.    case EXTERN_H+GLOBAL: printf("[Global and External from header file]\n"); break;
  218.    default:              ;
  219.    }
  220.  
  221.  if(option_xref&XREF_VAR)
  222.    {
  223.     if(var->scope&(GLOBAL|LOCAL))
  224.       {
  225.        for(i=0;i<var->visible.n;i++)
  226.           printf("   %s %s\n",i?"            ":"Visible in :",var->visible.s[i]);
  227.  
  228.        for(i=0;i<var->used.n;i++)
  229.           if(var->used.s[i][0]=='$')
  230.              printf("   %s %s\n",i?"            ":"Used in    :",&var->used.s[i][1]);
  231.           else
  232.              printf("   %s %s\n",i?"            ":"Used in    :",var->used.s[i]);
  233.       }
  234.    }
  235.  
  236.  printf("\n");
  237. }
  238.  
  239.  
  240. /*++++++++++++++++++++++++++++++++++++++
  241.   Print out the information for a typedef.
  242.  
  243.   Typedef type The typedef to output the information for.
  244.   ++++++++++++++++++++++++++++++++++++++*/
  245.  
  246. static void OutputTypedef(Typedef type)
  247. {
  248.  if(type->type)
  249.     printf("Typedef: %s = %s\n",type->name,type->type);
  250.  else
  251.     printf("Type   : %s\n",type->name);
  252.  
  253.  printf("\n");
  254. }
  255.